﻿using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

namespace LogNet6.SqlServer;
/// <summary>
/// SqlServer日志扩展
/// </summary>
public static class SqlServerLoggerServiceExtension
{
    /// <summary>
    /// 
    /// </summary>
    /// <param name="services"></param>
    /// <param name="connetionString">连接字符串</param>
    /// <param name="projectName">项目名称</param>
    /// <returns></returns>
    public static IServiceCollection AddSqlServerLogger(this IServiceCollection services, string connetionString, string projectName)
    {
        services.AddLogging(ii =>
        {
            ii.ClearProviders();
            ii.Services.AddSingleton<ILoggerProvider, LoggerProvider>();
        });
        return services.AddSingleton(x => new SqlServerLoggerProcessService(connetionString, projectName))
             .AddSingleton<ILoggerProcessor>(serviceProvider => serviceProvider.GetRequiredService<SqlServerLoggerProcessService>())
             .AddSingleton<ISqlServerLoggerProcessor>(serviceProvider => serviceProvider.GetRequiredService<SqlServerLoggerProcessService>());

    }



}

